# -*- coding: utf-8 -*-
# @Time : 2022/1/5 14:14
# @Author : Limusen
# @File : demo_log_24

# log日志demo

import os
import logging
import time

current_path = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
logs_path = os.path.join(current_path, 'logs')

# logger输入的地址
login_name = os.path.join(logs_path, 'Test_%s.log' % time.strftime("%Y_%m_%d"))

# 创建logger对象
logger = logging.getLogger("logger")
# logger的等级 info
logger.setLevel(20)

fh = logging.FileHandler(login_name, 'a', encoding="utf-8")  # 输出日志到文件
fh.setLevel(20)
ch = logging.StreamHandler()  # 输出日志到控制台
ch.setLevel(20)

logger.addHandler(fh)
logger.addHandler(ch)
fh.close()  # 关闭以免重复打印
ch.close()

logger.info("测试一下")
